import requests
import os
url = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
}

def save( hero_name, name, img_url):
    filename = f'{hero_name}\\'
    if not os.path.exists(filename):
        os.mkdir(filename)

    img_content = requests.get(url=img_url).content
    with open(filename + name + '.jpg', mode='wb') as f:
        f.write(img_content)


response = requests.get(url=url, headers=headers)
heroes = response.json()['hero']
for hero in heroes:
    hero_id = hero['heroId']
    hero_url = f'https://game.gtimg.cn/images/lol/act/img/js/hero/{hero_id}.js'
    response_1 = requests.get(url=hero_url, headers=headers)
    skins = response_1.json()['skins']
    for index in skins:
        title = index['heroTitle']
        hero_name = index['heroName']+title
        img_name = index['name']
        img_url = index['mainImg']
        if img_url:
            save(hero_name, img_name,img_url)
        else:
            img_url = index['chromaImg']
    print(title)









